package cookinmaddy.database.spod;
import cookinmaddy.model.RecipeIngredient;

class DBRecipeIngredientManager extends php.db.Manager<DBRecipeIngredient> 
{
	public function new() 
	{
		super(DBRecipeIngredient);
	}
  
    override function make( c : DBRecipeIngredient ) : Void 
	{
		trace("BEGIN");
		c.value = new RecipeIngredient();
		c.value.ingredient = DBIngredient.manager.fromId(c.ing_id);
		c.value.unit = DBUnit.manager.fromId(c.uni_id);
		c.value.quantity = c.quantity;
	}
  
    override function unmake( c : DBRecipeIngredient ) : Void 
	{
		trace("BEGIN");
		c.rec_id = c.value.recipe.ID;
		c.ing_id = c.value.ingredient.ID;
		c.uni_id = c.value.unit.ID;
		c.quantity = c.value.quantity;
		trace("END");
	}	
	
  public function allRecipeIngredients() : List<RecipeIngredient>
  {
	  trace("BEGIN");
	  var list : List<RecipeIngredient> = new List<RecipeIngredient>();
	  var alldbRecipeIngredients = super.all();
	  for (a in alldbRecipeIngredients)
	  {
		  list.add(a.value);
	  }
	  trace("END");
	  return list;
  }
}